//
//  MeRequest.m
//  BrushFace
//
//  Created by Harry on 16/1/26.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "MeRequest.h"
#import "NavStatus.h"
@implementation MeRequest

+(void)sendUserDataWithType:(USER_INFO_TYPE)type AndUserData:(NSMutableDictionary *)params success:(resultSuccess)resultSuccess error:(resultError)resultError
{
    NSMutableString *requestUrl = [[NSMutableString alloc]initWithString:SERVICE_ADRESS];
    switch (type)
      {
        case nickName:
        {
            [requestUrl appendString:@"/user/updatenickname4app.json?"];
        }
            break;
        case sexy:
        {
          
            [requestUrl appendString:@"/user/updatesex4app.json?"];
        }
            break;
          case age:
          {
              [requestUrl appendString:@"/user/updateage4app.json?"];
          }
              break;
          case education:
          {
              [requestUrl appendString:@"/user/updategraduate4app.json?"];
          }
              break;
          case address:
          {
              [requestUrl appendString:@"/user/updatelive4app.json?"];
          }
              break;
          case homeAddress:
          {
              [requestUrl appendString:@"/user/updatehome4app.json?"];
          }
              break;

          case industry:
          {
              [requestUrl appendString:@"/user/updateindustry4app.json?"];
          }
              break;
          case company:
          {
              [requestUrl appendString:@"/user/updatecompany4app.json?"];
          }
              break;
        default:
            break;
    }
    
    NSLog(@"%@%@",requestUrl,params);

    UIViewController * _curVC = [[NavStatus sharedInstance]getCurVC];
    [_curVC loadHud:_curVC.view];
    [_curVC showHudIndeterminate:@"正在保存 ..."];
    @weakify(_curVC);
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    manager.requestSerializer.timeoutInterval = 20;
    [manager GET:requestUrl parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        @strongify(_curVC);
//        [_curVC hideHudSuccess:@"上传成功"];
        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSString *string = [NSString stringWithFormat:@"%@",jsonObject[@"result"]];
        if ([string intValue]==1)
        {
             [_curVC hideHudSuccess:@"已选择"];
        }
        
        if (resultSuccess) {
            resultSuccess(jsonObject);
        }
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        @strongify(_curVC);
        [_curVC hideHudFailed:@"保存失败"];
        if (resultError) {
            resultError(error);
        }
        ITLogSP(@"error:%@",error.description);
    }];


}
@end
